#!/usr/bin/env python

import functools, os
import requests


def count():    # 闭包
    l = []
    for j in range(1, 4):
        def f():
            return j * j
        l.append(f)
    return l

a, b, c = count()
print(a(), b(), c())


def log():
    def log_decorator(f):
        def fn():
            print('调用了函数' + f.__name__ + '()')
            return f()
        return fn
    return log_decorator


@log()
def count1():   # 闭包改进1
    l = []
    for j in range(1, 4):
        def temp(k):
            def f():
                return k * k
            return f
        r = temp(j)
        l.append(r)
    return l

a, b, c = count1()
print(a(), b(), c())


def count2():   # 改进2
    l = []
    for k in range(1, 4):
        def f(j = k):
            return j*j
        l.append(f)
    return l

a1, a2, a3 = count2()
print(a1(), a2(), a3())


